package com.bbs.db.impl;

import com.bbs.db.iface.UserinfoDao;
import com.bbs.db.pers.Userinfo;
import java.util.List;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * @time Nov 12, 2009, 9:25:57 PM
 * @author fdcube
 */
public class UserinfoImpl extends HibernateDaoSupport implements UserinfoDao {

    public boolean AddUser(Userinfo value) {
        try {
            this.getHibernateTemplate().save(value);
            return true;
        } catch (DataAccessException dataAccessException) {
            logger.error(dataAccessException);
            return false;
        }
    }

    public boolean DeleteUser(Userinfo value) {
        try {
            Userinfo utmp = this.getHibernateTemplate().get(Userinfo.class, value.getUid());
            this.getHibernateTemplate().delete(utmp);
            return true;
        } catch (DataAccessException dataAccessException) {
            logger.error(dataAccessException);
            return false;
        }
    }

    public boolean UpdateUser(Userinfo value) {
        try {
            this.getHibernateTemplate().merge(value);
            return true;
        } catch (DataAccessException dataAccessException) {
            logger.error(dataAccessException);
            return false;
        }
    }

    public List<Userinfo> FindUser(Userinfo value) {
        return this.getHibernateTemplate().findByNamedParam("FROM Userinfo AS u WHERE u.uname =:uname AND u.upwd =:upwd", new String[]{"uname", "upwd"}, new String[]{value.getUname(), value.getUpwd()});
    }
    public List<Userinfo> FindUserById(Userinfo value) {
        return this.getHibernateTemplate().findByNamedParam("FROM Userinfo AS u WHERE u.uid =:uid", "uid", value.getUid());
    }

    public List<Userinfo> FindUsers() {
        return this.getHibernateTemplate().find("FROM Userinfo ORDER BY uid");
    }
}
